#!/usr/bin/python3
import sys
import re

# part 1

def contained(starts, ends):
    return (starts[0] <= starts[1] and ends[0] >= ends[1]) or (starts[1] <= starts[0] and ends[1] >= ends[0])

def part1():
    total = 0
    for line in sys.stdin:
        groups = re.match(r'^([0-9]+)-([0-9]+),([0-9]+)-([0-9]+)$', line.strip()).groups()
        starts = (int(groups[0]), int(groups[2]))
        ends = (int(groups[1]), int(groups[3]))
        total += 1 if contained(starts, ends) else 0
    print(f'{total} pairs have a range that fully contains the other')

# part 2

def overlap(starts, ends):
    return (starts[0] <= starts[1] and ends[0] >= starts[1]) or (starts[1] <= starts[0] and ends[1] >= starts[0])

def part2():
    total = 0
    for line in sys.stdin:
        groups = re.match(r'^([0-9]+)-([0-9]+),([0-9]+)-([0-9]+)$', line.strip()).groups()
        starts = (int(groups[0]), int(groups[2]))
        ends = (int(groups[1]), int(groups[3]))
        total += 1 if overlap(starts, ends) else 0
    print(f'{total} pairs have overlap')


if sys.argv[1] in '1':
    part1()
else:
    part2()